﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class Account_Group : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
        SqlCommand cmd;

        Int32 lastId = 0;


        try
        {
            conn.Open();

            cmd = new SqlCommand("INSERT INTO [Group] ([Name],[Owner],[Date]) OUTPUT INSERTED.ID VALUES(@Name, @UserId, @Date)", conn);
            cmd.Parameters.AddWithValue("@Userid", Page.User.Identity.Name);
            cmd.Parameters.AddWithValue("@Name", tbName.Text);
            cmd.Parameters.AddWithValue("@Date", DateTime.Now);
            lastId = (Int32)cmd.ExecuteScalar();

            
          
           

        }
        finally
        {
            conn.Close();
            Response.Redirect(string.Format("~/Account/ViewGroup.aspx?id={0}", lastId));
        }
    }
}